<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>博客列表</title>
		<link rel="stylesheet" href="css/conmmon.css">
		<link rel="stylesheet" href="css/blog_list.css">
		<script src="js/jquery.min.js"></script>
		<script src="js/logout.js"></script>
	</head>
	<body>
		<div class="nav">
			<img src="img/logo2.jpg" alt="">
			<span class="title">我的博客系统</span>
			<span class="spacer"></span>
			<a href="blog_list.html">博客论坛</a>
			<a href="blog_add.html">写博客</a>
			<a href="javascript:logout()">注销</a>
		</div>
		<div class="container">
			<div id="artListDiv" class="container-right" style="margin: 10%;"></div>
		</div>
		<script>
			function init(){
				jQuery.ajax({
					url:"/art/mylist",
					type:"GET",
					data:{},
					success:function(res){
						if(res.code==200){
							var createhtml="";
							var list=res.data;
							if(list==null||list.length==0){
								createhtml+="<h3 style='margin-left:20px;margin-top:20px'>暂无文章，请"+"<a href='blog_add.html'>添加</a></h3>";
							}else{
								for(var i=0;i<list.length;i++){
									var item=list[i];
									createhtml+='<div class="blog">';
									createhtml+='<div class="title">'+item.title+'</div>';
									createhtml+='<div class="date">'+item.createtime+'</div>';
									createhtml+='<div class="desc">'+item.content+'</div>';
									createhtml+='<a href="blog_content.html?id='+item.id+'" class="detail">查看全文 &gt;&gt;</a>&nbsp;&nbsp;';
									createhtml+='<a href="blog_edit.html?id='+item.id+'" class="detail">修改 &gt;&gt;</a>&nbsp;&nbsp;';
									createhtml+='<a onclick="del('+item.id+')" class="detail">删除 &gt;&gt;</a>';
									createhtml+='</div>';
								}
							}
							jQuery("#artListDiv").html(createhtml);
						}else{
							alert("操作失败："+res.msg);
						}
					}
				});
			}
			init();
			
			function del(id){
				if(id==""||id<=0){
					alert("参数错误");
					return false;
				}
				jQuery.ajax({
					url:"/art/del",
					type:"POST",
					data:{
						"id":id
					},
					success:function(res){
						if(res.code==200){
							alert("删除成功");
							location.href=location.href;
						}else{
							alert("操作失败："+res.msg);
						}
					}
				});
			}
		</script>
	</body>
</html>